package cn.com.sp.demo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import cn.com.sp.demo.socket.SocketManager;

@Component//被spring容器管理
@Order(2)
public class SocketRunner implements ApplicationRunner{
	
	public static Map<String,SocketManager> socketMap = new HashMap<>();
	
	

	private static Logger LOG = LoggerFactory.getLogger(SocketRunner.class);
	@SuppressWarnings("resource")
	@Override
	public void run(ApplicationArguments args) throws Exception {
		/*new Thread(
		new Runnable(){
			@Override
			public void run() {
				LOG.info("SocketRunner =============== start");
				ServerSocket serverSocket = null;
				try {
					serverSocket = new ServerSocket(8024);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				for(;;){
				Socket socket = null;
				try {
					socket = serverSocket.accept();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				SocketManager tt = new SocketManager(socket);
				tt.start();
				}
			}
		}).start();
*/
		
	}
}
